home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / ease-3.5 / src / errors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-15  |  5.1 KB  |  227 lines

  1. #ifdef FLUKE
  2. # ifndef LINT
  3.     static char RCSid[] = "@(#)FLUKE  $Header: /tmp_mnt/home/kreskin/u0/barnett/Src/Ease/ease/src/RCS/errors.c,v 2.3 1991/09/09 16:33:23 barnett Exp $";
  4. # endif LINT
  5. #endif FLUKE
  6.  
  7. /*
  8.  *      errors.c   -- Contains error initialization and reporting routines.
  9.  *
  10.  *      author     -- James S. Schoner, Purdue University Computing Center,
  11.  *                        West Lafayette, Indiana  47907
  12.  *
  13.  *      date       -- July 9, 1985
  14.  *
  15.  *    Copyright (c) 1985 by Purdue Research Foundation
  16.  *
  17.  *    All rights reserved.
  18.  *
  19.  * $Log: errors.c,v $
  20.  * Revision 2.3  1991/09/09  16:33:23  barnett
  21.  * Minor bug fix release
  22.  *
  23.  * Revision 2.2  1991/05/16  10:45:25  barnett
  24.  * Better support for System V machines
  25.  * Support for machines with read only text segments
  26.  *
  27.  * Revision 2.1  1990/01/30  14:17:29  jeff
  28.  * Bruce Barnett - extensions for SunOS/Ultrix.
  29.  *
  30.  * Revision 2.0  88/06/15  14:41:10  root
  31.  * Baseline release for net posting. ADR.
  32.  */
  33.  
  34. #include <stdio.h>
  35. #include "fixstrings.h"
  36. #include <ctype.h>
  37. extern int  ErrorCount;     /* error count                   */
  38. extern char FNbuf[];     /* input file name              */
  39. extern int  Lcount;     /* line count                    */
  40. FILE *DIAGf = {stderr};  /* file for diagnostic output */
  41. extern char yytext[];    /* current token */
  42. extern int yyleng;    /* and it's length */
  43. extern int    yylineno;    /* current input line number */
  44. extern char *infile;        /* input file name */
  45. static char *source;
  46.  
  47. /*
  48.  * yywhere() -- input position for yyparse()
  49.  * from Schreiner and Friedman's book on compiler construction
  50.  */
  51. void
  52. yywhere()     /* position stamp */
  53. {
  54.     char    colon = 0;    /* flag */
  55.     if (source && *source && strcmp(source,"\"\"")) {
  56.     char    *cp = source;
  57.     int    len = strlen(source);
  58.     
  59.     if (*cp == '"')
  60.       ++cp, len -= 2;
  61.     if (strlen(cp, "./", 2) == 0)
  62.       cp += 2, len -= 2;
  63.     if (len > 0 )
  64.       fprintf(DIAGf, "\"%.*s\"", len, cp);
  65.     colon = 1;
  66.     }     else if (infile && strcmp(infile,"-")) {
  67.       fprintf(DIAGf, "\"%s\"",infile);
  68.       colon = 1;
  69.       }
  70.     if (yylineno > 0 ) {
  71.     if (colon)
  72.       fputs(", ",DIAGf);
  73.     fprintf(DIAGf, "line %d",
  74.         yylineno - (*yytext == '\n' || ! *yytext));
  75.     colon = 1;
  76. /*    if ((yylineno - (*yytext == '\n' || ! *yytext)) != Lcount)
  77.       fprintf(DIAGf, "?%d:?", Lcount); */
  78.     }
  79.     if (*yytext) {
  80.     register int i;
  81.     for (i=0;i<20;++i)
  82.       if (!yytext[i] || yytext[i] == '\n')
  83.         break;
  84.     if (i) {
  85.         if (colon)
  86.           putc(' ',DIAGf);
  87.         fprintf(DIAGf, "near \"%.*s\"",i,yytext);
  88.         colon = 1;
  89.     }
  90.     }
  91.     if (colon)
  92.       fputs(": ",DIAGf);
  93.     fflush(DIAGf);
  94.     fflush(stdout);
  95.     fflush(stderr); /* just to make sure */
  96. }
  97.  
  98.  
  99. /*
  100.  *    yymark - keep track of source file and line number 
  101.  */
  102.  
  103. void
  104. yymark()    /* retreive from '# digit text' */
  105. {
  106.     if (source)
  107.       cfree(source); 
  108.     source = (char *) calloc(yyleng,sizeof(char));
  109.     if (source) {
  110.       sscanf(yytext, "# %d%s",&yylineno, source);
  111. /*      fprintf(stderr,"source = '%s' on %s",source,yytext); */
  112.       Lcount = yylineno;
  113.       if (strcmp(source,"\"\""))
  114.     strcpy(FNbuf,source);
  115.       else if ( infile && strcmp(infile,"-"))
  116.     sprintf(FNbuf,"\"%s\"",infile);
  117. /*      fprintf(stderr,"FNbuf = '%s', infile = '%s'\n",FNbuf,infile); */
  118.            
  119.   }
  120. }
  121.  
  122.  
  123.  
  124. /*
  125.  *    yyerror () -- Prints source file name (FNbuf), line number (Lcount),
  126.  *              and error message (sbErr) for each invokation.
  127.  *              it also prints out a message where the error is.
  128.  *
  129.  */
  130. void
  131. yyerror (sbErr)
  132. char *sbErr;
  133. {
  134.     extern int yynerrs;
  135.     ++ErrorCount;
  136.     yywhere();
  137. /*    fprintf(DIAGf, " %s\t[error %d]\n", sbErr, ErrorCount); */
  138.     fprintf(DIAGf, " %s\n", sbErr);
  139. /* yynerrs is the number of yacc errors, ErrorCount is larger */
  140. }
  141.  
  142.  
  143.  
  144. /*
  145.  *    ErrorReport () -- Prints source file name (FNbuf), line number (Lcount),
  146.  *              and error message (sbErr) for each invokation.
  147.  *
  148.  */
  149. void
  150. ErrorReport (sbErr)
  151. char *sbErr;
  152. {
  153. /*    fprintf (DIAGf, "%s, line %d: %s", FNbuf, Lcount, sbErr);
  154.     ErrorCount++; */
  155.     yyerror(sbErr);
  156. }
  157.  
  158.  
  159. /*
  160.  *    FatalError () -- Translator fatal error routine which prints 
  161.  *             error message (sbErr) and an argument (sbArg).
  162.  *
  163.  */
  164. void
  165. FatalError (sbErr, sbArg)
  166. char *sbErr,
  167.      *sbArg;
  168. {
  169.     fprintf (DIAGf, "%s, line %d: Fatal Error In Translator: %s %s\n", 
  170.          FNbuf, Lcount, sbErr, sbArg); 
  171.     fflush(stderr);
  172.     exit (1);
  173. }
  174.  
  175.  
  176. /*
  177.  *    PrintError () -- Prints source file name (FNbuf), line number
  178.  *             (cline), error message (sbErr), and argument
  179.  *             (sbArg) for each invokation.
  180.  *
  181.  */
  182. void
  183. PrintError (sbErr, sbArg)
  184. char *sbErr;
  185. char *sbArg;
  186. {
  187.     char    Ebuffer[1000];
  188.     sprintf(Ebuffer,sbErr,sbArg);
  189.     yyerror(Ebuffer);
  190. /*    fprintf (DIAGf, "%s, line %d: %s %s.\n", FNbuf, Lcount, sbErr, sbArg);
  191.     ErrorCount++; */
  192. }
  193.  
  194.  
  195. /*
  196.  *    PrintWarning () -- Prints a warning message with source file
  197.  *               name (FNbuf), line number (Lcount), warning
  198.  *               (sbWarn), and a possible identifier (sbID).
  199.  *
  200.  */
  201. void
  202. PrintWarning (sbWarn, sbID)
  203. char *sbWarn;
  204. char *sbID;
  205. {
  206. /*    fprintf (DIAGf, "%s, line %d: Warning: ", FNbuf, Lcount); */
  207.         yywhere();
  208.     fprintf(DIAGf,"Warning: ");
  209.     if (sbID != NULL)
  210.         fprintf (DIAGf, sbWarn, sbID);
  211.     else
  212.         fprintf (DIAGf, sbWarn);
  213. }
  214.  
  215.  
  216. /*
  217.  *    InitError () -- Initialize line count (Lcount) to one and error count
  218.  *                (ErrorCount) to zero.
  219.  *
  220.  */
  221. void
  222. InitError ()
  223. {
  224.     Lcount     = 1;
  225.     ErrorCount = 0;
  226. }
  227.